<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 2021/10/8
  Time: 16:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户登录</title>
    <script src="${pageContext.request.contextPath}/js/jquery-3.3.1.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/jquery.md5.js"></script>
    <link href="${pageContext.request.contextPath}/css/customer/login.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/common.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/js/customer/jsencrypt.js"></script>
    <link href="http://r1nxp2i0y.hn-bkt.clouddn.com/images/ico.png" rel="icon" type="image/x-ico"/>

</head>
<body>
<span id="message_id" style="font-size: 10px;color: red">
</span>
<div class="login-img">
        <div class="w1180">
            <div class="login">
                <div class="login-left">
                    <img style="   border-top-left-radius: 9px; border-bottom-left-radius: 9px" src="http://r1nxp2i0y.hn-bkt.clouddn.com/images/login-left1.jpg">
                    <div class="login-left-text">
                        <div class="login-left-top">
                            <span></span>
                            "注册即享好礼"
                            <span></span>
                        </div>
                        <ul class="login-left-logo">
                            <li>
                                <span class="icon">减</span>
                                <p>登录就送优惠卷</p>
                            </li>
                            <li>
                                <span class="icon">￥</span>
                                <p>优惠满减满足你</p>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="login-right">
                    <form  class="form1" >
                    <div class="login-right-top">
                        <h3>会员登录</h3>
                    </div>
                    <!--                <div class="login-right-top1">-->
                    <!--                </div>-->
                    <div class="login-right-main">
                        <ul class="login-right-main1">
                            <li>
                                <input class="username" name="custTel" type="text" placeholder="请输入你的手机号" maxlength="11"/>
                                <span class="username-msg"></span>
                            </li>
                            <li>
                                <input class="password" name="custPassword" type="password" placeholder="请输入密码"/>
                                <span class="password-msg"></span>
                            </li>
                        </ul>
                        <div class="login-right-text">
                            <p><input id = "must" type="checkbox"  checked="checked"/>
                                <span class="must-msg"></span>
                                未注册小橘租车账号的手机号，登录时将自动注册，且代表你已同意
                                <a href="">《小橘租车会员注册协议》</a>和
                                <a href="" >《小橘租车隐私政策》</a>
                            </p>
                        </div>
                        <div class="login-right-btn">
                            <input type="button" class="btn-popup" value="登录"/>
<%--                            <a href="" title="登录" class="btn-popup">登录</a>--%>
                        </div>

                        <div class="login-last">
                            还没账号？
                            <a href="${pageContext.request.contextPath}/customer/register">立即注册</a>
                        </div>
                    </div>
                    </form>
<%--                    ${loginMsg}--%>
                </div>
            </div>
        </div>
</div>
<script src="${pageContext.request.contextPath}/js/customer/login.js"></script>
<%--<script>--%>
<%--$(".btn-popup").click(function () {--%>
<%--    var salt = "springbootdemo";--%>
<%--    var newPassword = $.md5($(".password").val()+salt);--%>
<%--    var custTel = $(".username").val();--%>

<%--    $.post( "${pageContext.request.contextPath}/customer/login",--%>
<%--        {--%>
<%--            custTel:custTel,--%>
<%--            custPassword:newPassword--%>
<%--        },--%>
<%--        function (result){--%>
<%--            if(result.code == 200){--%>
<%--                console.log("登录成功")--%>
<%--                window.location.href="${pageContext.request.contextPath}"--%>
<%--            }--%>
<%--            else--%>
<%--                $("#message_id").text("用户名或密码错误，请重新登录。");--%>
<%--        },--%>
<%--        "json");--%>
<%--})--%>
<%--</script>--%>
<%--判断--%>
<script>

</script>

<script>

    var PUBLIC_KEY = '';

    $(".btn-popup").click(function () {
var cheked = document.querySelector("#must").checked;
console.log("试试"+cheked);
        if(cheked){
        $.ajax({
            type: "GET",
            url: "${pageContext.request.contextPath}/publickey",
            dataType: 'json',
            success: function (result) {
                PUBLIC_KEY = result.data; //获取公钥

                var encrypt = new JSEncrypt();
                encrypt.setPublicKey('-----BEGIN PUBLIC KEY-----' + PUBLIC_KEY + '-----END PUBLIC KEY-----');

                // var username = $(".username").val();
                // var encryptusername = encrypt.encrypt(username);

                // alert( $(".password").val());

                var password = $(".password").val();
                var encryptpassword = encrypt.encrypt(password);
                console.log("公钥:%o",PUBLIC_KEY);
                console.log("加密后的数据:%o",encryptpassword);
                var tel = $(".username").val();
                console.log("手机号"+tel);

                $.ajax({
                    type:"POST",
                    url: "${pageContext.request.contextPath}/login",
                    data: {
                        custTel:tel,
                        custPassword:encryptpassword
                    },
                    success: function (result1) {

                                if(result1.code==200){
                            console.log("测试一次"+result1.code);
                            console.log("测试测试");
                            window.location.href="${pageContext.request.contextPath}"
                        }else {
                            $("#message_id").text("用户名或密码错误，请重新登录。");
                            <%--window.location.href="${pageContext.request.contextPath}/customer/login"--%>

                        }
                    },
                    dataType:  "json"
                });

                // console.log('公钥:%o', PUBLIC_KEY);
                // console.log('加密后数据:%o', encrypted);

                // $(".username").val(encryptusername);
                // $(".password").val(encryptpassword);
                // $("form1").submit();

            }
        });
        }else if(cheked==false){
            document.querySelector(".must-msg").innerText="请勾选安全协议";
        }
    });


</script>

</body>
</html>
